package com.itheima.controller;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.itheima.dao.CustomerMapper;
import com.itheima.po.Customer;
import com.itheima.service.CustomerService;
import com.itheima.service.CustomerServiceImpl;
/**
 * 控制器类
 */

public class CustomerController implements Controller{
	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			               HttpServletResponse response)  {
		
		//CustomerService customerService = new CustomerServiceImpl();
	    ApplicationContext act = 
	            new ClassPathXmlApplicationContext("applicationContext.xml");
	    CustomerService customerService = act.getBean(CustomerService.class);  
	    List<Customer> customerList = customerService.findCustomerAll();
	    
         // 创建ModelAndView对象
		ModelAndView mav = new ModelAndView();
		
         // 向模型对象中添加数据
		mav.addObject("customerList", customerList);
         // 设置逻辑视图名
		mav.setViewName("/WEB-INF/jsp/customer.jsp");
         // 返回ModelAndView对象
		return mav;
	}
}
